<template>
  <el-menu 
    :ellipsis="true"
    :router="false"
    class="route"
    text-color="#fff"
    background-color="transparent"
    menu-trigger="hover"
    :default-openeds="['0']"
    style="max-width: 140px; border: none"
    @open="handleOpen"
    @close="handleClose"
  >
    <div v-for="(item, index) in Routes" :key="index">
      <div v-if="item.children && item.children.length > 0">
        <el-sub-menu :index="index.toString()">
          <template #title>
            <div class="title">
              <span>{{ item.Name }}</span>
            </div>
          </template>
          <el-menu-item
            v-for="el in item.children"
            :key="el.path"
            :index="el.path"
            class="routeItem"
            :class="{ active: path === el.path }"
            @click="onSelectNav(el)"
          >
            <div class="title">
              <span>{{ el.Name }}</span>
            </div>
          </el-menu-item>
          <!-- <el-menu-item-group>
            <el-menu-item v-for="(el, elindex) in item.children" :key="elindex" class="routeItem" :index="el.path" :class="{ active: path === item.path }" @click="onSelectNav(item)">
              <div class="title">
                <span>{{ el.Name }}</span>
              </div>
            </el-menu-item>
          </el-menu-item-group> -->
        </el-sub-menu>
      </div>
      <div v-else>
        <el-menu-item :index="index" class="routeItem" :class="{ active: path === item.path }" @click="onSelectNav(item)">
          <div class="title">
            <span>{{ item.Name }}</span>
          </div>
        </el-menu-item>
      </div>
    </div>
  </el-menu>
</template>

<script lang="ts" setup>
const route = useRoute();
const emit = defineEmits(['onSelectNav', 'saveCallBack']);
const props = defineProps({
  Routes: {
    type: Array,
    default: () => []
  },
  path: {
    type: String,
    default: ''
  }
});
// 默认激活的菜单
// const path = computed(() => {
//   let path = route.path;
//   return path;
// });
const onSelectNav = (item) => {
  console.log('item', item);

  emit('onSelectNav', item);
};
const handleOpen = (key: string, keyPath: string[]) => {
  console.log(key, keyPath);
};
const handleClose = (key: string, keyPath: string[]) => {
  console.log(key, keyPath);
};
const getindex = (index, elindex) => {
  const str = `${index}-${elindex}`;
  console.log('str', str);
  return str;
};
</script>

<style lang="scss" scoped>
.el-menu--horizontal.el-menu {
  border-bottom: none;
  display: flex;
  justify-content: flex-start;
}

.el-menu {
  flex: 1;
  height: 100%;
  font-family: 'YouSheBiaoTiHei';
  .el-menu-item,
  .el-sub-menu {
    .title {
      flex: 1;
      font-size: 20px;
      height: 100%;
      width: 100px;
      display: flex;
      align-items: center;
    }
  }
}

.routeItem {
  display: flex;
  height: 50px;
  justify-content: space-around;
  align-items: center;
  border-radius: 5px 0px 0px 5px;

  // &:hover {
  //   background: linear-gradient(-90deg, rgba(45, 203, 240, 0) 0%, rgba(45, 211, 250, 0.96) 99%);
  // }

  &.active {
    // border: 1px solid #1f5f6e;
    // background: url('@/assets/common/xz.png') no-repeat -4px 0px / 100% 145%;
    color: rgb(64, 158, 255);
  }
}
</style>

<style lang="scss" setup>
:deep(.el-menu--horizontal) :deep(.el-menu) :deep(.el-menu-item) {
  height: 50px !important;
}

:deep(.el-menu--horizontal) :deep(.el-menu) :deep(.el-menu--popup) {
  padding: 0px !important;
}

:deep(.el-popper.is-pure) {
  background-color: #1f5f6e;

  div {
    ul {
      padding: 0px;
    }
  }
}
</style>